<?php
//标签设定
class labelController extends adminController{
    protected $layout = 'layout';
    //标签列表
    public function index(){
        $act = in($_GET['act']);
        if($act == 'del'){
            $fid = intval($_GET['id']);
            $result =  model('label')->Del($fid);
            if($result){
                echo 1;
            }else{
                echo '删除失败!';
            } 
        }else{
            $listRows = 20; //每页条数
            $url = url('label/index',array('page'=>'{page}'));
            $allcount = model('label')->count();
            $limit = $this->pageLimit($url,$listRows);
            $this->page= $this->pageShow($allcount);
            $this->list =model('label')->select(null,null,null,$limit); 
            $this->display('label/index');
        }
    }
    //标签添加
    public function add(){
        if($this->isPost()){
                $msg = Check::rule(array(check::must($_POST['title']),'标签名称必须填写'));
                if(true !== $msg){
                    $this->jsonMsg($msg);
                }
                $fid = intval($_POST['fid']);
                $_POST['uptime'] = time();
                $data = postinput($_POST,array('fid'));
                $info = model('label')->Save($fid,$data); //插入模型数据
                if($info){
                    $this->jsonMsg('标签添加成功！请返回',1,url('label/index'));
                }else{
                    $this->jsonMsg('标签添加失败！请返回');
                }
        }else{
            $this->type = $_GET['type'];
            if($this->type == 1){
                $this->display('label/channel_label');
            }
            if($this->type == 2){
                $this->special = model('special')->getClass(0);
                $this->display('label/content_label');
            }
        }
    }
    //编辑
    public function edit(){
        $this->type = $_GET['type'];
        $this->channel = model('channel')->getClass(0);
        $this->fid = intval($_GET['id']);
        $condition['id']= $this->fid;
        $this->info = model('label')->find($condition);
        if($this->type == 1){
            $this->display('label/channel_label');
        }
        if($this->type == 2){
            $this->special = model('special')->getClass(0);
            $this->display('label/content_label');
        }
        if($this->type == 3){
            $this->display('label/diy_label');
        }
    }
}